package code._15network.tcp.v1;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Service {
    public static void main(String[] args) throws IOException {
        //创建套接字、绑定端口
        ServerSocket serverSocket = new ServerSocket(8888);
        //accept接收链接
        Socket clientSocket = serverSocket.accept();
        //获取输入流、读取信息
        InputStream in = clientSocket.getInputStream();
        //打印信息、关闭socket（两个）
        byte[] bytes = new byte[1024];
        int readCount=in.read(bytes);
        String msg = new String(bytes, 0, readCount);
        System.out.println("msg = " + msg);
        serverSocket.close();
        clientSocket.close();
    }
}
